<?php
class top extends spController
{
	//重定义构造函数
    function __construct(){  
        parent::__construct(); 
		//导航
        $c = $this->spArgs('c','','get');$c = $c==""?"main":$c;	$this->c = $c;
        $a = $this->spArgs('a','','get');$a = $a==""?"index":$a; $this->a = $a;

        //页面内容
        $page_content_id = array(
            "main_index" => 47,
            "intro_index"=> 47,
            "notice_index"=> 54,
            "news_index"=> 48,
            "resource_index"=> 55,
            'comment_index' => 49,
            'join_index'    => 67,
            'meeting_index' => 57,

            'online_intro' => 66,
            'online_date' => 66,
            'online_file' => 66,
            );
        
        if(isset($page_content_id[$c."_".$a])){

            $page_content_where = spClass("m_url")->findAll(array("cat_id"=>$page_content_id[$c."_".$a]),"weight DESC");

            foreach ($page_content_where as $key => $value) {
                $src_arr = explode(",",$value["content"]);
                if( in_array($src_arr[0],array('article','comment','page','url')) && is_numeric($src_arr[1])){

                    if($src_arr[0] != "page"){
                        if( $src_arr[0] == "comment" ){
                            $sort = "time DESC";
                            $where = array("cat_id"=>$src_arr[1],"visible"=>1);
                        }else{
                            $sort = "weight DESC,add_time DESC";
                            $where = array("cat_id"=>$src_arr[1],"visible"=>1);
                        }
                    }else{
                        $sort = "add_time DESC";
                        $where = array("cat_id"=>$src_arr[1]);
                    }

                    $target_table_class = spClass("m_".$src_arr[0]);
                    $result[$src_arr[0]][] = $target_table_class->spPager($this->spArgs('page', 1), 10)->findAll($where,$sort);
                    $pager[$src_arr[0]][] = $target_table_class->spPager()->getPager();


                }
            }
            $this->cat = $page_content_where;
            $this->result = $result;
            
            $this->pager = $pager;
        }

		//网站信息
		$setting = spClass("m_setting");	
		$setting_result = $setting->findAll();
	
		$this->cms_title = $setting_result[0]['content'];
		$this->cms_description = $setting_result[1]['content'];
		$this->cms_address = $setting_result[2]['content'];
		$this->cms_keywords = $setting_result[3]['content'];

		$this->cms_phone = $setting_result[4]['content'];
		$this->cms_email = $setting_result[5]['content'];

		$this->cms_record = $setting_result[6]['content'];
        $this->cms_ann = $setting_result[7]['content'];

        $this->cms_is_time_visible = $setting_result[8]['content'];
        
		$this->page_title = $this->cms_title;

        $this->email_server_address = $setting_result[9]['content'];
        $this->email_server_username = $setting_result[10]['content'];
        $this->email_server_password = $setting_result[11]['content'];
        $this->email_recieve_address = $setting_result[12]['content'];
        $this->web_shouye_info = $setting_result[13]['content'];
    } 
    //获取评论列表
    //$module 模型类型 article/picture/page/url/feedback
    //$module_id 模型id id
    //$page 页数
    function comment_list($module,$module_id){
    	if(!isset($module)){
    	   	$data = $this->spArgs();
    		extract($data);    		
    	}

    	if(isset($module)&&is_numeric($module_id)){
    		$comment = spClass('m_comment');
    		$page = $this->spArgs('page');
    		$this->comment_result = $comment->spPager(is_numeric($page)?$page:1, 5)->findAll(array('module'=>$module,'module_id'=>$module_id),'time DESC');
            $this->pager = $comment->spPager()->getPager();
    		$this->c = $this->spArgs('c');
    		$this->a = $this->spArgs('a');
            $this->notice = $this->spArgs('notice');

    	}
    }
    //添加评论信息
    function comment_add($module,$module_id,$father_id,$other_item,$other_content){
    	$data = $this->spArgs();
    	extract($data);

    	if(isset($module)&&is_numeric($module_id)){
    		$comment = spClass('m_comment');
    		$other_item = implode(',', $other_item);
    		$other_content = implode(',', $other_content);
    		$data = array(
    				'module' => $module,
    				'module_id' => $module_id,
    				'father_id' => isset($father_id)?$father_id:0,
    				'user_id' => isset($user_id)?$user_id:0,
    				'content' => $content,
    				'other_item' => $other_item,
    				'other_content' => $other_content,
    		 );
    		if($comment->create($data))
    			$this->jump($jump_url);
    	}
    }
}
